app.config(function($stateProvider, $urlRouterProvider) {
  $stateProvider
  /*持证标准管理*/
  .state('position.position_certificate_standard', {
    url: '/position_certificate_standard/:position_id',
    templateUrl: 'app/partials/position_certificate_standard/index.html',
    controller: function($scope,$location,PositionCertificateStandard, $stateParams, Position) {
      $scope.widget_title = '持证要求管理';
      $scope.position = Position.get({id: $stateParams.position_id});
      $scope.position_certificate_standards = PositionCertificateStandard.get_position_standards({position_id: $stateParams.position_id});
      /* 删除 记录*/
      $scope.itemDelete = function(item){
        PositionCertificateStandard.delete({},{"id": $scope.position_certificate_standards[item].id})
        $scope.position_certificate_standards.splice(item, 1); 
      }
      /* 编辑*/ 
      $scope.itemEdit = function(item){
        $location.url("/position/position_certificate_standard/"+ $stateParams.position_id + "/edit/" + item )
      }
      
   }
  })

  /*添加持证标准*/
  .state('position.position_certificate_standard.new', {
    url: '/new',
    templateUrl: 'app/partials/position_certificate_standard/form.html',
    controller: function($scope,$state,PositionCertificateStandard,Position,Certificate,RequireCertificateOrgan, $stateParams) {
      $scope.widget_title = '添加持证要求';
      $scope.certificates = Certificate.query();
      $scope.require_certificate_organs = RequireCertificateOrgan.query();
      
      $scope.update = function(position_certificate_standard){
        position_certificate_standard.position_id = $stateParams.position_id
        console.log(position_certificate_standard);
        PositionCertificateStandard.save(position_certificate_standard, function(nr){
          $scope.position_certificate_standards.push(nr["result"]);
          console.log(nr)
        });
        $scope.position_certificate_standard = {};
        $state.transitionTo('position.position_certificate_standard',$stateParams,{reload: true});  
        
      }
    }
  })

  /*编辑持证标准*/
  .state('position.position_certificate_standard.edit', {
    url: '/edit/:id',
    templateUrl: 'app/partials/position_certificate_standard/form.html',
    controller: function($scope,$state,PositionCertificateStandard,Position,Certificate,RequireCertificateOrgan, $stateParams) {
      
      $scope.widget_title = '编辑持证要求';
      $scope.certificates = Certificate.query();
      $scope.require_certificate_organs = RequireCertificateOrgan.query();
      $scope.position_certificate_standard = PositionCertificateStandard.get({id: $stateParams.id})
      
      
      $scope.update = function(position_certificate_standard){
        position_certificate_standard.position_id = $stateParams.position_id
        console.log(position_certificate_standard);
        PositionCertificateStandard.save(position_certificate_standard, function(nr){
          $scope.position_certificate_standards.push(nr["result"]);
          console.log(nr)
        });
        $scope.position_certificate_standard = {};
        $state.transitionTo('position.position_certificate_standard',$stateParams,{reload: true}); 
        
      }
    }
  })
})